/**
 * 世纪高通地图添加散点标记
 * @param mapObject：地图对象
 * @param markerOption: 点标记配置
 * @return MapMarker：点标记对象实例
 */
class MapMarker {
    constructor(mapObject, markerOption) {
        let longitude = import.meta.env.VITE_MAP_CENTER_LONGITUDE
        let latitude = import.meta.env.VITE_MAP_CENTER_LATITUDE
        this.mapObject = mapObject;
        this.markerOption = Object.assign({
            lnglat: [longitude, latitude], // 点标记经纬度
            pkId: "",
            properties: {},
            url: "url(/ivam/mapPin.png)", // 点标记图片路径
            width: "40px", // 点标记图片宽度
            height: "46px", // 点标记图片高度
            duration: 0 //延时时间毫秒，规定时间后删除点标记
        }, markerOption);
        this.el = document.createElement("div");
        this.el.style["background-image"] = this.markerOption.url;
        this.el.style.width = this.markerOption.width;
        this.el.style.height = this.markerOption.height;
        this.el.style["background-size"] = "100% 100%";
        this.el.addEventListener("click", () => {
            this.onClick();
        });
        this.marker = new minemap.Marker(this.el, {
            anchor: "center",
            rotationAlignment: "map",
        })
            .setLngLat(this.markerOption.lnglat)
            .addTo(this.mapObject);
        if (this.markerOption.duration) {
            setTimeout(() => {
                this.remove();
            }, this.markerOption.duration);
        }
    }
    remove() {
        this.marker.remove();
    }
    onClick() {
        if (this.clickCallback) {
            this.clickCallback();
        }
    }
    registerOnClickHandler(callback) {
        this.clickCallback = callback;
    }
}
export default MapMarker;